package com.app.controler;

import com.app.base.BaseController;
import com.app.entity.Student;
import com.app.request.QueryRequest;
import com.app.response.ApiListResponse;
import com.app.response.ApiResponse;
import com.app.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 * @author lijh
 */
@RestController
@Api(value = "学生信息前端控制器", tags = "学生信息前端控制器")
@RequestMapping("/student")
public class StudentController extends BaseController {
    @Autowired
    IStudentService iStudentService;


    @ResponseBody
    @ApiOperation(value = "测试1", notes = "测试1")
    @RequestMapping(value="/hello",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
    public ApiResponse hello() {
        //insert
        Student student = new Student();
        student.setStuName("zhangsan");
        student.setStuNumber("001");
        student.setAge(23);
        iStudentService.save(student);
        return ApiResponse.ok();
    }

    @ResponseBody
    @ApiOperation(value = "测试2-分页", notes = "测试2-分页")
    @RequestMapping(value="/hello2",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
    public ApiListResponse<Student> hello2(@ModelAttribute QueryRequest request) {
        //如果要分页
        startPage(request);
        List<Student> list = iStudentService.selectStudentByStuName(request);
        return ApiListResponse.ok(list);
    }
}
